<!-- HTML header for doxygen 1.9.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>CMSIS-Core (Cortex-M): Startup File startup_&lt;Device&gt;.c</title>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="tabs.js"></script>
<script type="text/javascript" src="footer.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
  $(document).ready(function() { init_search(); });
/* @license-end */
</script>
<script type="text/javascript" src="darkmode_toggle.js"></script>
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
<link href="extra_navtree.css" rel="stylesheet" type="text/css"/>
<link href="extra_search.css" rel="stylesheet" type="text/css"/>
<link href="extra_tabs.css" rel="stylesheet" type="text/css"/>
<link href="version.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../version.js"></script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 55px;">
  <td id="projectlogo" style="padding: 1.5em;"><img alt="Logo" src="cmsis_logo_white_small.png"/></td>
  <td style="padding-left: 1em; padding-bottom: 1em;padding-top: 1em;">
   <div id="projectname">CMSIS-Core (Cortex-M)
   &#160;<span id="projectnumber"><script type="text/javascript">
     <!--
     writeHeader.call(this);
     writeVersionDropdown.call(this, "CMSIS-Core (Cortex-M)");
     //-->
    </script>
   </span>
   </div>
   <div id="projectbrief">CMSIS-Core support for Cortex-M processor-based devices</div>
  </td>
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <span id="MSearchSelect"                onmouseover="return searchBox.OnSearchSelectShow()"                onmouseout="return searchBox.OnSearchSelectHide()">&#160;</span>
          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
</td>
  <!--END !PROJECT_NAME-->
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<div id="CMSISnav" class="tabs1">
  <ul class="tablist">
    <script type="text/javascript">
      writeComponentTabs.call(this);
    </script>
  </ul>
</div>
<script type="text/javascript">
  writeSubComponentTabs.call(this);
</script>
<!-- Generated by Doxygen 1.9.6 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('startup_c_pg.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div><div class="header">
  <div class="headertitle"><div class="title">Startup File startup_&lt;Device&gt;.c </div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><a class="anchor" id="md_src_core_startup_c"></a> The startup file defines device exceptions and interrupts, and provides their initial (weak) handler functions. The file has a naming convention <code>startup_&lt;Device&gt;.c</code> where <code>&lt;Device&gt;</code> corresponds to the device name.</p>
<p>Specifically, following functionalities are provided in the startup file:</p>
<ul>
<li>The reset handler <code>Reset_Handler</code> which is executed upon CPU reset and typically calls the <code><a class="el" href="group__system__init__gr.html#ga93f514700ccf00d08dbdcff7f1224eb2" title="Function to Initialize the system.">SystemInit()</a></code> function. After the system init the control is transferred to the C/C++ run-time library which performs initialization and calls the <code>main</code> function in the user code.</li>
<li>The setup values for the Main Stack Pointer (MSP).</li>
<li>Exception vectors of the Cortex-M Processor with weak functions that implement default routines.</li>
<li>Interrupt vectors that are device specific with weak functions that implement default routines.</li>
</ul>
<p>To adapt the file to a specific device only the interrupt vector table needs to be extended with the device-specific interrupt handlers. The naming convention for the interrupt handler names is <code>&lt;interrupt_name&gt;_IRQHandler</code>. This table needs to be consistent with <a class="el" href="group__NVIC__gr.html#ga7e1129cd8a196f4284d41db3e82ad5c8">IRQn_Type</a> that defines all the IRQ numbers for each interrupt.</p>
<p>Additional application-specific adaptations may be required in the startup code and therefore so the startup file shall be located in the application project. <a class="el" href="cmsis_files_dfps.html">Delivery in CMSIS-Packs</a> explains how this can be achieved when device support is provided in <a href="https://open-cmsis-pack.github.io/Open-CMSIS-Pack-Spec/main/html/index.html">CMSIS pack format</a>.</p>
<p><b>Example:</b></p>
<p>The following example shows the extension of the interrupt vector table for the LPC1100 device family.</p>
<div class="fragment"><div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment">  Exception / Interrupt Handler</span></div>
<div class="line"><span class="comment"> *----------------------------------------------------------------------------*/</span></div>
<div class="line"><span class="comment">/* Exceptions */</span></div>
<div class="line"><span class="keywordtype">void</span> WAKEUP0_IRQHandler     (<span class="keywordtype">void</span>) __attribute__ ((weak, alias(<span class="stringliteral">&quot;Default_Handler&quot;</span>)));</div>
<div class="line"><span class="keywordtype">void</span> WAKEUP1_IRQHandler     (<span class="keywordtype">void</span>) __attribute__ ((weak, alias(<span class="stringliteral">&quot;Default_Handler&quot;</span>)));</div>
<div class="line"><span class="keywordtype">void</span> WAKEUP2_IRQHandler     (<span class="keywordtype">void</span>) __attribute__ ((weak, alias(<span class="stringliteral">&quot;Default_Handler&quot;</span>)));</div>
<div class="line"><span class="comment">// :</span></div>
<div class="line"><span class="comment">// :</span></div>
<div class="line"><span class="keywordtype">void</span> EINT1_IRQHandler       (<span class="keywordtype">void</span>) __attribute__ ((weak, alias(<span class="stringliteral">&quot;Default_Handler&quot;</span>)));</div>
<div class="line"><span class="keywordtype">void</span> EINT2_IRQHandler       (<span class="keywordtype">void</span>) __attribute__ ((weak, alias(<span class="stringliteral">&quot;Default_Handler&quot;</span>)));</div>
<div class="line"><span class="comment">// :</span></div>
<div class="line"><span class="comment">// :</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment">  Exception / Interrupt Vector table</span></div>
<div class="line"><span class="comment"> *----------------------------------------------------------------------------*/</span></div>
<div class="line"><span class="keyword">extern</span> <span class="keyword">const</span> pFunc <a class="code hl_define" href="group__compiler__conntrol__gr.html#gab94ebeb20055f1848d7b707d3c7cfc5d">__VECTOR_TABLE</a>[240];</div>
<div class="line">       <span class="keyword">const</span> pFunc <a class="code hl_define" href="group__compiler__conntrol__gr.html#gab94ebeb20055f1848d7b707d3c7cfc5d">__VECTOR_TABLE</a>[240] <a class="code hl_define" href="group__compiler__conntrol__gr.html#ga4f65c96effa79fbd610fea43ee7d745b">__VECTOR_TABLE_ATTRIBUTE</a> = {</div>
<div class="line">  (pFunc)(&amp;<a class="code hl_define" href="group__compiler__conntrol__gr.html#ga1002e751427b1189f92787d4e4eef965">__INITIAL_SP</a>),                   <span class="comment">/*     Initial Stack Pointer */</span></div>
<div class="line">  Reset_Handler,                            <span class="comment">/*     Reset Handler */</span></div>
<div class="line">  NMI_Handler,                              <span class="comment">/* -14 NMI Handler */</span></div>
<div class="line">  HardFault_Handler,                        <span class="comment">/* -13 Hard Fault Handler */</span></div>
<div class="line">  MemManage_Handler,                        <span class="comment">/* -12 MPU Fault Handler */</span></div>
<div class="line">  BusFault_Handler,                         <span class="comment">/* -11 Bus Fault Handler */</span></div>
<div class="line">  UsageFault_Handler,                       <span class="comment">/* -10 Usage Fault Handler */</span></div>
<div class="line">  0,                                        <span class="comment">/*     Reserved */</span></div>
<div class="line">  0,                                        <span class="comment">/*     Reserved */</span></div>
<div class="line">  0,                                        <span class="comment">/*     Reserved */</span></div>
<div class="line">  0,                                        <span class="comment">/*     Reserved */</span></div>
<div class="line">  SVC_Handler,                              <span class="comment">/*  -5 SVC Handler */</span></div>
<div class="line">  DebugMon_Handler,                         <span class="comment">/*  -4 Debug Monitor Handler */</span></div>
<div class="line">  0,                                        <span class="comment">/*     Reserved */</span></div>
<div class="line">  PendSV_Handler,                           <span class="comment">/*  -2 PendSV Handler */</span></div>
<div class="line">  SysTick_Handler,                          <span class="comment">/*  -1 SysTick Handler */</span></div>
<div class="line"> </div>
<div class="line">  <span class="comment">/* Interrupts */</span></div>
<div class="line">  WAKEUP0_IRQHandler,                       <span class="comment">/*   0 Wakeup PIO0.0 */</span></div>
<div class="line">  WAKEUP1_IRQHandler,                       <span class="comment">/*   1 Wakeup PIO0.1 */</span></div>
<div class="line">  WAKEUP2_IRQHandler,                       <span class="comment">/*   2 Wakeup PIO0.2 */</span></div>
<div class="line">  <span class="comment">// :</span></div>
<div class="line">  <span class="comment">// :</span></div>
<div class="line">  EINT1_IRQHandler,                         <span class="comment">/*  30 PIO INT1 */</span></div>
<div class="line">  EINT2_IRQHandler,                         <span class="comment">/*  31 PIO INT2 */</span></div>
<div class="line">  <span class="comment">// :</span></div>
<div class="line">  <span class="comment">// :</span></div>
<div class="line">};</div>
<div class="ttc" id="agroup__compiler__conntrol__gr_html_ga1002e751427b1189f92787d4e4eef965"><div class="ttname"><a href="group__compiler__conntrol__gr.html#ga1002e751427b1189f92787d4e4eef965">__INITIAL_SP</a></div><div class="ttdeci">#define __INITIAL_SP</div><div class="ttdoc">Compiler/linker symbol specifying the location of the main stack (MSP).</div><div class="ttdef"><b>Definition:</b> ref_compiler_ctrl.txt:484</div></div>
<div class="ttc" id="agroup__compiler__conntrol__gr_html_ga4f65c96effa79fbd610fea43ee7d745b"><div class="ttname"><a href="group__compiler__conntrol__gr.html#ga4f65c96effa79fbd610fea43ee7d745b">__VECTOR_TABLE_ATTRIBUTE</a></div><div class="ttdeci">#define __VECTOR_TABLE_ATTRIBUTE</div><div class="ttdoc">Additional decl specs to be used when defining the (static) interrupt vector table.</div><div class="ttdef"><b>Definition:</b> ref_compiler_ctrl.txt:533</div></div>
<div class="ttc" id="agroup__compiler__conntrol__gr_html_gab94ebeb20055f1848d7b707d3c7cfc5d"><div class="ttname"><a href="group__compiler__conntrol__gr.html#gab94ebeb20055f1848d7b707d3c7cfc5d">__VECTOR_TABLE</a></div><div class="ttdeci">#define __VECTOR_TABLE</div><div class="ttdoc">Symbol name used for the (static) interrupt vector table.</div><div class="ttdef"><b>Definition:</b> ref_compiler_ctrl.txt:520</div></div>
</div><!-- fragment --><h1><a class="anchor" id="startup_c_sec"></a>
startup_Device.c Template File</h1>
<p>CMSIS-Core <a class="el" href="cmsis_device_files.html#cmsis_template_files">Device Template Files</a> include a <code>startup_Device.c</code> file that can be used as a starting point for chip vendors to implement own device-specific startup file.</p>
<p>The C startup file relys on certain compiler specific preprocessor defines specified in CMSIS compiler headers:</p>
<ul>
<li><a class="el" href="group__compiler__conntrol__gr.html#ga1002e751427b1189f92787d4e4eef965">__INITIAL_SP</a></li>
<li><a class="el" href="group__compiler__conntrol__gr.html#ga84b0bad4aa39632d3faea46aa1e102a8">__STACK_LIMIT</a></li>
<li><a class="el" href="group__compiler__conntrol__gr.html#ga72db8b026c5e100254080fefabd9fd88">__PROGRAM_START</a></li>
<li><a class="el" href="group__compiler__conntrol__gr.html#gab94ebeb20055f1848d7b707d3c7cfc5d">__VECTOR_TABLE</a></li>
<li><a class="el" href="group__compiler__conntrol__gr.html#ga4f65c96effa79fbd610fea43ee7d745b">__VECTOR_TABLE_ATTRIBUTE</a></li>
<li><a class="el" href="group__stacksealing__support__trustzone__functions.html#gacc36ddac1642fe80a690364911542d79">__STACK_SEAL</a> (for Armv8-M/v8.1-M)</li>
<li><a class="el" href="group__stacksealing__support__trustzone__functions.html#ga87d2473a3adebb73941065366feec690">__TZ_set_STACKSEAL_S</a> (for Armv8-M/v8.1-M)</li>
</ul>
<p>The stack sealing and the initialization for the Stack Limit register is done in function <code>Reset_Handler(void)</code>:</p>
<div class="fragment"><div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment">  Reset Handler called on controller reset</span></div>
<div class="line"><span class="comment"> *----------------------------------------------------------------------------*/</span></div>
<div class="line"><a class="code hl_define" href="group__compiler__conntrol__gr.html#ga153a4a31b276a9758959580538720a51">__NO_RETURN</a> <span class="keywordtype">void</span> Reset_Handler(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">  <a class="code hl_function" href="group__Core__Register__gr.html#ga48e5853f417e17a8a65080f6a605b743">__set_PSP</a>((uint32_t)(&amp;<a class="code hl_define" href="group__compiler__conntrol__gr.html#ga1002e751427b1189f92787d4e4eef965">__INITIAL_SP</a>));</div>
<div class="line"> </div>
<div class="line">  <a class="code hl_function" href="group__Core__Register__gr.html#ga6809a07c5cb7410e361f3fba57f72172">__set_MSPLIM</a>((uint32_t)(&amp;<a class="code hl_define" href="group__compiler__conntrol__gr.html#ga84b0bad4aa39632d3faea46aa1e102a8">__STACK_LIMIT</a>));</div>
<div class="line">  <a class="code hl_function" href="group__Core__Register__gr.html#ga4348d14fc5eefbfd34ab8c51be44a81b">__set_PSPLIM</a>((uint32_t)(&amp;<a class="code hl_define" href="group__compiler__conntrol__gr.html#ga84b0bad4aa39632d3faea46aa1e102a8">__STACK_LIMIT</a>));</div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#if defined (__ARM_FEATURE_CMSE) &amp;&amp; (__ARM_FEATURE_CMSE == 3U)</span></div>
<div class="line">  <a class="code hl_function" href="group__stacksealing__support__trustzone__functions.html#ga87d2473a3adebb73941065366feec690">__TZ_set_STACKSEAL_S</a>((uint32_t *)(&amp;<a class="code hl_define" href="group__stacksealing__support__trustzone__functions.html#gacc36ddac1642fe80a690364911542d79">__STACK_SEAL</a>));</div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"> </div>
<div class="line">  <a class="code hl_function" href="group__system__init__gr.html#ga93f514700ccf00d08dbdcff7f1224eb2">SystemInit</a>();                             <span class="comment">/* CMSIS System Initialization */</span></div>
<div class="line">  <a class="code hl_define" href="group__compiler__conntrol__gr.html#ga72db8b026c5e100254080fefabd9fd88">__PROGRAM_START</a>();                        <span class="comment">/* Enter PreMain (C library entry point) */</span></div>
<div class="line">}</div>
<div class="ttc" id="agroup__Core__Register__gr_html_ga4348d14fc5eefbfd34ab8c51be44a81b"><div class="ttname"><a href="group__Core__Register__gr.html#ga4348d14fc5eefbfd34ab8c51be44a81b">__set_PSPLIM</a></div><div class="ttdeci">void __set_PSPLIM(uint32_t ProcStackPtrLimit)</div><div class="ttdoc">Set Process Stack Pointer Limit Devices without Armv8-M Main Extensions (i.e. Cortex-M23) lack the no...</div></div>
<div class="ttc" id="agroup__Core__Register__gr_html_ga48e5853f417e17a8a65080f6a605b743"><div class="ttname"><a href="group__Core__Register__gr.html#ga48e5853f417e17a8a65080f6a605b743">__set_PSP</a></div><div class="ttdeci">void __set_PSP(uint32_t topOfProcStack)</div><div class="ttdoc">Set the PSP register.</div></div>
<div class="ttc" id="agroup__Core__Register__gr_html_ga6809a07c5cb7410e361f3fba57f72172"><div class="ttname"><a href="group__Core__Register__gr.html#ga6809a07c5cb7410e361f3fba57f72172">__set_MSPLIM</a></div><div class="ttdeci">__set_MSPLIM(uint32_t MainStackPtrLimit)</div><div class="ttdoc">Set Main Stack Pointer Limit Devices without Armv8-M Main Extensions (i.e. Cortex-M23) lack the non-s...</div></div>
<div class="ttc" id="agroup__compiler__conntrol__gr_html_ga153a4a31b276a9758959580538720a51"><div class="ttname"><a href="group__compiler__conntrol__gr.html#ga153a4a31b276a9758959580538720a51">__NO_RETURN</a></div><div class="ttdeci">#define __NO_RETURN</div><div class="ttdoc">Inform the compiler that a function does not return.</div><div class="ttdef"><b>Definition:</b> ref_compiler_ctrl.txt:182</div></div>
<div class="ttc" id="agroup__compiler__conntrol__gr_html_ga72db8b026c5e100254080fefabd9fd88"><div class="ttname"><a href="group__compiler__conntrol__gr.html#ga72db8b026c5e100254080fefabd9fd88">__PROGRAM_START</a></div><div class="ttdeci">#define __PROGRAM_START</div><div class="ttdoc">Entry function into the user application or library startup.</div><div class="ttdef"><b>Definition:</b> ref_compiler_ctrl.txt:472</div></div>
<div class="ttc" id="agroup__compiler__conntrol__gr_html_ga84b0bad4aa39632d3faea46aa1e102a8"><div class="ttname"><a href="group__compiler__conntrol__gr.html#ga84b0bad4aa39632d3faea46aa1e102a8">__STACK_LIMIT</a></div><div class="ttdeci">#define __STACK_LIMIT</div><div class="ttdoc">Compiler/linker symbol specifying the limit of the main stack (MSP).</div><div class="ttdef"><b>Definition:</b> ref_compiler_ctrl.txt:507</div></div>
<div class="ttc" id="agroup__stacksealing__support__trustzone__functions_html_ga87d2473a3adebb73941065366feec690"><div class="ttname"><a href="group__stacksealing__support__trustzone__functions.html#ga87d2473a3adebb73941065366feec690">__TZ_set_STACKSEAL_S</a></div><div class="ttdeci">void __TZ_set_STACKSEAL_S(uint32_t *stackTop)</div><div class="ttdoc">Set stack seal at given address (secure)</div></div>
<div class="ttc" id="agroup__stacksealing__support__trustzone__functions_html_gacc36ddac1642fe80a690364911542d79"><div class="ttname"><a href="group__stacksealing__support__trustzone__functions.html#gacc36ddac1642fe80a690364911542d79">__STACK_SEAL</a></div><div class="ttdeci">#define __STACK_SEAL</div><div class="ttdoc">Compiler/linker symbol specifying the location of the stack seal.</div><div class="ttdef"><b>Definition:</b> ref_trustzone.txt:411</div></div>
<div class="ttc" id="agroup__system__init__gr_html_ga93f514700ccf00d08dbdcff7f1224eb2"><div class="ttname"><a href="group__system__init__gr.html#ga93f514700ccf00d08dbdcff7f1224eb2">SystemInit</a></div><div class="ttdeci">void SystemInit(void)</div><div class="ttdoc">Function to Initialize the system.</div></div>
</div><!-- fragment --><blockquote class="doxtable">
<p>&zwj;<b>Note</b></p><ul>
<li>Stack Sealing also requires the application project to use a scatter file (or a linker script) as explained in <a class="el" href="using_TrustZone_pg.html#RTOS_TrustZone_stacksealing">Stack Sealing</a> section. </li>
</ul>
</blockquote>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">
      <script type="text/javascript">
        <!--
        writeFooter.call(this);
        //-->
      </script> 
    </li>
  </ul>
</div>
</body>
</html>
